﻿Imports System.Windows.Forms
Imports LRS.DTO

Public Class ucCust
    Private CustID As Integer
    Public Function ucValidateCust() As Boolean
        If txtFirstName.Text.Length = 0 Or txtLastName.Text.Length = 0 Or txtHomeTown.Text.Length = 0 Or txtAddress.Text.Length = 0 Or txtPhone.Text.Length = 0 Or txtSocialID.Text.Length = 0 Then
            MessageBox.Show("Bạn vui lòng điền đầy đủ thông tin!")
            txtFirstName.Focus()
            Return False
        End If
        If txtSocialID.Text Like "[0-9]*" Then
            Return True
        Else
            MessageBox.Show("Số CMND không đúng định dạng!")
            txtSocialID.Text = ""
            txtSocialID.Focus()
            Return False
        End If
        If txtEmail.Text Like "*@[A-Z,a-z,0-9]*.*" Then
            Return True
        Else
            MessageBox.Show("Địa chỉ Email không đúng định dạng!")
            txtEmail.Text = ""
            txtEmail.Focus()
            Return False
        End If
        If txtPhone.Text Like "[0-9]*" Then
            Return True
        Else
            MessageBox.Show("Số điện thoại không đúng định dạng!")
            txtPhone.Text = ""
            txtPhone.Focus()
            Return False
        End If
        Return True
    End Function

    Public Sub SetCustomer(ByVal cust As eCustomer)
        txtFirstName.Text = cust.FirstName
        txtLastName.Text = cust.LastName
        txtAddress.Text = cust.CurrentAddress
        txtHomeTown.Text = cust.HometownAddress
        txtEmail.Text = cust.Email
        txtPhone.Text = cust.Phone
        txtSocialID.Text = cust.SocialID
        radMale.Checked = cust.Gender
        dtBirthday.Value = cust.DateOfBirth
        CustID = cust.CustomerID
    End Sub
    Public Function GetCustomer() As eCustomer
        Dim cust As eCustomer = New eCustomer()
        cust.FirstName = txtFirstName.Text
        cust.LastName = txtLastName.Text
        cust.CurrentAddress = txtAddress.Text
        cust.HometownAddress = txtHomeTown.Text
        cust.Email = txtEmail.Text
        cust.Phone = txtPhone.Text
        cust.SocialID = txtSocialID.Text
        cust.Gender = radMale.Checked
        cust.DateOfBirth = dtBirthday.Value
        cust.CustomerID = CustID
        Return cust
    End Function
    Public Sub ClearText()
        For Each c As Control In grpCust.Controls
            If (TypeOf c Is TextBox) Then
                c.ResetText()
            End If
        Next
    End Sub

    Private Sub radMale_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radMale.CheckedChanged
        If (radMale.Checked = False) Then
            radFemale.Checked = True
        End If
    End Sub
End Class
